// 泛型接口
interface TestInterface<T> {
    TestInterface run(T data);
}

// 泛型类实现泛型接口
class Test<T> implements TestInterface<T> {
    private T data;
    public T num = null;

    public Test(T data) {
        this.data = data;
    }

    public TestInterface run(T data) {
        this.data = data;
        return this;
    }

    public T get() {
        return data;
    }

    public Test set(T data) {
        this.data = data;
        return this;
    }
}


class Base {

}

class Student extends Base {

}

class SmallStudent extends Student {

}

public class GenericsTest {
    //泛型方法 传递普通泛型
    static public <K> K func(K data) {
        if (data.equals(data))
            System.out.println(data);
        return data;
    }

    //泛型方法 传递泛型数组
    static public <K> K [] func(K [] data) {
        for (K t: data) {
            System.out.print(t + " ");
        }
        System.out.println();
        return data;
    }

    //泛型方法 传递泛型对象
    static public <E> void show(Test<E> o) {
        System.out.println("test = " + o.get());
    }

    // 普通方法传递泛型对象
    static public void show2(Test<Double> o) {
        // o.num = 678.89;
        o.set(4667.778);
        System.out.println("test = " + o.get());
    }

    // 普通方法传递泛型对象 进行限制
    // static public void show3(Test<? extends Student> o) {
    static public void show3(Test<? super Student> o) {
        // o.num = 678.89;
        // o.set(4667.778);
        System.out.println("test = " + o.get());
    }

    static public void main(String [] args) {
        // Test<Integer> o = new Test<Integer>(30);
        // Test<Double> o = new Test<Double>(30.4567);
        // Test<Student> o = new Test<Student>(new Student());
        Test<Base> o = new Test<Base>(new Base());
        // Test<SmallStudent> o = new Test<SmallStudent>(new SmallStudent());

        // o.run(7893.57);

        // int s = func(356);
        // String s = func("sjdfkl");
        // double s = func(35.78);

        // o.set(78);

        // show2(o);
        show3(o);
    }
}
